package utils

import java.text.SimpleDateFormat
import java.util.Date

object timeUtils {
  // 2019/12/27 19:41:52.754
  def tranTimeb2bfh(timestamp: String): Long = {
    val fm1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS")
    fm1.parse(timestamp).getTime
  }

  def tranTimeb2bhy(timestamp: String): Long = {
    val fm1 = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS")
    fm1.parse(timestamp).getTime + 8 * 60 * 60 * 1000
  }

  def formatTime(timestamp: Long): Date = {
    val dm2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:00")
    dm2.parse(dm2.format(timestamp))
  }

  def formatStartLong(starttime: Long): Long = {
    val time = formatTime(starttime)
    val dm3 = new SimpleDateFormat("mm")
    time.getTime - dm3.format(time).toLong % 5 * 60 * 1000
  }

  def formatEndLong(endtime: Long): Long = {
    val dm3 = new SimpleDateFormat("mm")
    val time = formatTime(endtime)
    time.getTime + (5 - dm3.format(time).toLong % 5) * 60 * 1000
  }

  def formatTimeTemp = (timeStampTemp: Long) => {
    val format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    format.format(timeStampTemp + 5 * 60 * 1000)
  }

}
